﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using DevEnverModal;
using QuailDashboard.View.Models;
using QuailDashboard.View.QuailServiceReference;

namespace QuailDashboard.View.Controls
{
    public partial class EnvironmentSettingsControl : UserControl
    {
        private readonly PageState _pageState = new PageState();

        public EnvironmentSettingsControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Gets or sets the ModalControl manager for this instance
        /// </summary>
        public ModalControl Modal
        {
            get;
            set;
        }

        public event EventHandler Finished;

        public TestEnvironment Environment
        {
            get
            {
                return _pageState.Environment;
            }

            set
            {
                _pageState.Environment = value;
            }
        }

        private void Close()
        {
            Modal.HideModal();
            if (Finished != null)
                Finished(this, EventArgs.Empty);
        }

        private void ButtonCancel_Click(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            LayoutRoot.DataContext = _pageState;
        }

        private void ButtonUpdate_Click(object sender, RoutedEventArgs e)
        {

        }

        private class PageState : IsProcessingStateModel
        {
            private TestEnvironment _environment;

            public string Caption
            {
                get
                {
                    if (_environment == null)
                        return "Edit";

                    return "Edit Settings for " + _environment.Description;
                }
            }

            public TestEnvironment Environment
            {
                get
                {
                    return _environment;
                }
                
                set
                {
                    _environment = value;
                    NotifyPropertyChanged("Environment");
                    NotifyPropertyChanged("Caption");
                }
            }
        }
    }
}
